Skip to content

Let a list as the last positional field take the remaining arguments in rfl::cli - #36

Open
clockblocker wants to merge 1 commit into
wave-base-8from
cli-list-positional
Open

clockblocker wants to merge 1 commit into
wave-base-8from
cli-list-positional

Conversation

@clockblocker

@clockblocker clockblocker commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

Lets a list declared as the last rfl::Positional field consume all remaining positional arguments in rfl::cli::read, instead of failing with Too many positional arguments. Purely additive.

Example

struct Config {
  rfl::Positional<std::string> command;
  rfl::Positional<std::vector<std::string>> files;
  rfl::DefaultVal<bool> verbose = false;
};

// Before: Too many positional arguments: expected at most 2, got 3.
// After:  command="run", files={"a", "b", "c"}, verbose=true
rfl::cli::read<Config>({"run", "a,b", "--verbose", "c"});

// rfl::cli::usage<Config>("app"):
// Usage: app <command> <files>... [--verbose[=<bool>]]

Key details

  • Each remaining positional argument is split at commas and appended in order; plain lists require ≥1 argument, while std::optional / rfl::DefaultVal allow 0.
  • Long-option spelling (--files=a --files=b) still works, but mixing --files=... with bare positionals returns a conflict error.
  • Earlier positional list fields still consume a single argument; public resolve_args<T, Ps> keeps its one-per-field flat-map behavior.
  • Docs updated in cli.md ("A list as the last positional argument").

AI-authored. Depends on: #26.

…in rfl::cli

If the last positional field is a list, it takes every positional
argument after those of the other positional fields, each split at the
commas: `app run a b,c` gives files = [a, b, c]. A list before other
positional fields still takes one argument, and so does every positional
field in the public resolve_args<T>, whose flat-map result cannot hold
them.

usage shows a list as the last positional as `<files>...`.

Only inputs that used to fail change meaning.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant